package cn.chendd.bootsrtap;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;

/**
 * Seata事务的txId携带
 *
 * @author chendd
 * @date 2023/1/24 17:20
 */
public class SeataXidRequestInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate template) {
        boolean xid = template.headers().containsKey(RootContext.KEY_XID);
        if (! xid) {
            template.header(RootContext.KEY_XID , RootContext.getXID());
        }
    }
}
